﻿<?php
class User_ActionController extends Myh_Controller_Action
{
	protected $_arrParams;
	protected $_currentController;
	protected $_mainAction;
	public function init()
	{
		$this->_arrParams 			= $this->getRequest()->getParams();
		$this->_currentController 	= '/' . $this->_arrParams['module'] .
									  '/' . $this->_arrParams['controller'];
		$this->_mainAction 			= '/' . $this->_arrParams['module'] .
							 		  '/' . $this->_arrParams['controller'] . 
							 		  '/' . 'index';
		$this->view->arrParams 			= $this->_arrParams;
		$this->view->currentContrller 	= $this->_currentController; 
		$this->view->mainAction			= $this->_mainAction;
		$templatePath					= APP_PATH . '/design/frontend/default/template';
		$this->loadTemplate($templatePath);
	}
	public function loginAction()
	{
		$this->view->title = 'Cộng đồng toán học Việt Nam - Đăng nhập';
		$this->view->headTitle($this->view->title, true);
		if($this->_request->isPost()){
			
		}
	}
	public function registerAction()
	{
		$this->view->title = 'Cộng đồng toán học Việt Nam - Đăng ký thành viên';
		$this->view->headTitle($this->view->title, true);
		$ns = new Zend_Session_Namespace('Myh_Cmath_Error');
		if($this->_request->isPost()){
			$validate = new User_Form_ValidateRegister($this->_arrParams);
			//print_r($this->_arrParams);
			if($validate->isError()){
				$ns->errors = $validate->getMsgError();
			}else{
				$tblUser = new User_Model_Users();
				$tblUser->addUser($this->_arrParams, array('action'=>'user-new'));
				$transport = array();
				$transport['host'] 		= 'mail.studentworkvietnam.com';
				$transport['username'] 	= 'support@studentworkvietnam.com';
				$transport['password'] 	= '1q2w3e4r5t#';
				$optionmail = array();
				$optionmail['fromemail'] 	= 'support@studentworkvietnam.com';
				$optionmail['fromname'] 	= 'Ban Quan Trị Gioitoan.com';
				$optionmail['toemail']	 	= $this->_arrParams['email'];
				$optionmail['toname'] 		= $this->_arrParams['full_name'];
				$body= 'Test Email ';
				$mail = new Myh_Mail();
				$mail->sendMail('[Cộng đồng toán học Việt Nam] Thông tin đăng ký thành viên', $body, $transport, $optionmail);
				$ns->unsetAll();
				$this->_redirect('/user/action/login');
			}
		}else{
			$ns->unsetAll();
		}
	}
}